package com.wkhyapp.lm.contract;

import com.wkhyapp.lm.base.BasePresenter;
import com.wkhyapp.lm.http.ApiCallback;
import com.wkhyapp.lm.http.net.AddGoodsRequest;
import com.wkhyapp.lm.http.net.BaseRequest;
import com.wkhyapp.lm.http.net.GoodsReq;
import com.wkhyapp.lm.http.net.SuperResponse;
import com.wkhyapp.lm.http.vo.Category;
import com.wkhyapp.lm.utils.MemberUtils;

/**
 * Created by fang on 2021/10/10.
 */

public class UpLoadPresenter extends BasePresenter<UploadView> {

    public UpLoadPresenter(UploadView uploadView) {
        super(uploadView);
    }

    public void  getToken(){
        BaseRequest request = new BaseRequest();
        request.setUserId(MemberUtils.getUid());
        addSubscription(apiStores.getUploadToken(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.setToken(response.getItem());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
            }
        });
    }

    public void  upload(GoodsReq addGoodsRequest){
        addSubscription(apiStores.addGoods(addGoodsRequest),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.upLoadSucc();
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
            }
        });
    }

    public void  getCategry(int userId){
        BaseRequest request = new BaseRequest();
        request.setUserId(userId);
        addSubscription(apiStores.userCategorys(request),new ApiCallback<SuperResponse<Category>>() {
            @Override
            public void onSuccess(SuperResponse<Category> response) {
                mvpView.setCategoory(response.getItems());
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }


    public void  updateGoods(GoodsReq request){
        addSubscription(apiStores.upateGoods(request),new ApiCallback<SuperResponse<String>>() {
            @Override
            public void onSuccess(SuperResponse<String> response) {
                mvpView.upLoadSucc();
            }
            @Override
            public void onFailure(String msg) {
//                mvpView.setfail("");
            }

            @Override
            public void onFinish() {
                mvpView.dismissLoad();
            }
        });

    }
}
